<?php
/**
 *@author Connor <caokang@foxmail.com>
 *@todo
 *@link www.zeevin.com
 */
class UserTages extends CActiveRecord{

	public $taglist;

	public function tableName(){
		return 'user_tags';
	}

	public function attributeLabels(){
		return  array('taglist' =>'添加标签' , );
	}
	public static function model($className=__CLASS__){
		return parent::model($className);
	}

	public function rules(){
		return array(
			array('taglist','required','on'=>'create','message'=>'标签内容不能为空'),
			);
	}
	
	public static function del($id){
		$count = UserTages::model()->countBySql('select count(1) from user_tags where uid=? and id=?',array(Yii::app()->user->id,$id));
		if($count==1){return UserTages::model()->deleteByPk($id);}
		else return false;
	}
	//查询id喜欢的标签id
	public static function getLike($id=false){
		$data = array();
		if(!$id)$id=Yii::app()->user->id;
		$rs = UserTages::model()->findAllByAttributes(array('uid'=>$id,'type'=>0));
		if($rs){
			foreach ($rs as $v) {
				$data[]=$v->tag_id;
			}
		}
		return $data;
	}

	//查询id排斥标签id
	public static function getHate($id=false){
		$data = array();
		if(!$id)$id=Yii::app()->user->id;
		$rs = UserTages::model()->findAllByAttributes(array('uid'=>$id,'type'=>1));
		if($rs){
			foreach ($rs as $v) {
				$data[]=$v->tag_id;
			}
		}
		return $data;
	}
}